<script setup lang="ts">
import { useEnv } from '@/store/useEnv'
import { DialogOptions, useDialog } from 'naive-ui'
import { getCurrentInstance } from 'vue'

const dialog = useDialog()
const ctx = getCurrentInstance()
ctx!.appContext.config.globalProperties.$dialog = dialog

if (useEnv().IS_ELECTRON) {
  const { ipcRenderer } = require('electron')
  ipcRenderer.on('dialog', (e, opts: DialogOptions) => {
    opts = Object.assign(
      {
        onClose: () => ipcRenderer.send('dialogRes', false),
        onMaskClick: () => ipcRenderer.send('dialogRes', false),
        onNegativeClick: () => ipcRenderer.send('dialogRes', false),
        onPositiveClick: () => ipcRenderer.send('dialogRes', true)
      } as DialogOptions,
      opts
    )
    dialog.create(opts)
  })
}
</script>
<template>
  <div></div>
</template>
